/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package morenoapp.components.common.table.renderer;

import java.awt.Color;
import java.awt.Component;
import javax.swing.JLabel;
import javax.swing.JTable;
import javax.swing.table.DefaultTableCellRenderer;

/**
 *
 * @author dmitry.mamonov
 */
public class StringRenderer extends DefaultTableCellRenderer {

    private String defaultMessage = "";

    public String getDefaultMessage() {
        return defaultMessage;
    }

    public void setDefaultMessage(String defaultMessage) {
        this.defaultMessage = defaultMessage;
    }

    @Override
    public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
        Component result = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
        if (isSelected) {
            result.setForeground(table.getSelectionForeground());
        } else {
            result.setForeground(table.getForeground());
        }
        if ("".equals(value)) {
            setText(defaultMessage);
            setForeground(Color.GRAY);
        }

        return result;
    }


}
